import 'dart:io';
import 'package:image/image.dart' as img;

void main() async {
  // 确保目录存在
  final directory = Directory('assets/icons');
  if (!await directory.exists()) {
    await directory.create(recursive: true);
  }

  // 创建主图标
  final mainIcon = img.Image(width: 1024, height: 1024);

  // 填充蓝色背景
  final backgroundColor = img.ColorRgb8(33, 150, 243);
  img.fill(mainIcon, color: backgroundColor);

  // 绘制白色对话框和箭头
  final foregroundColor = img.ColorRgb8(255, 255, 255);
  _drawTranslateIcon(mainIcon, foregroundColor);

  // 保存主图标
  final mainIconFile = File('assets/icons/app_icon.png');
  await mainIconFile.writeAsBytes(img.encodePng(mainIcon));

  // 创建前景图标
  final foregroundIcon = img.Image(width: 1024, height: 1024);

  // 绘制白色对话框和箭头
  _drawTranslateIcon(foregroundIcon, foregroundColor);

  // 保存前景图标
  final foregroundIconFile = File('assets/icons/app_icon_foreground.png');
  await foregroundIconFile.writeAsBytes(img.encodePng(foregroundIcon));

  print('Icons generated successfully!');
}

void _drawTranslateIcon(img.Image image, img.ColorRgb8 color) {
  // 绘制左侧对话框
  img.fillRect(
    image,
    x1: 205,
    y1: 307,
    x2: 461,
    y2: 614,
    color: color,
  );

  // 绘制右侧对话框
  img.fillRect(
    image,
    x1: 563,
    y1: 410,
    x2: 819,
    y2: 717,
    color: color,
  );

  // 绘制箭头
  // 水平线
  img.drawLine(
    image,
    x1: 412,
    y1: 512,
    x2: 612,
    y2: 512,
    color: color,
    thickness: 20,
  );

  // 左箭头
  img.drawLine(
    image,
    x1: 412,
    y1: 512,
    x2: 452,
    y2: 472,
    color: color,
    thickness: 20,
  );
  img.drawLine(
    image,
    x1: 412,
    y1: 512,
    x2: 452,
    y2: 552,
    color: color,
    thickness: 20,
  );

  // 右箭头
  img.drawLine(
    image,
    x1: 612,
    y1: 512,
    x2: 572,
    y2: 472,
    color: color,
    thickness: 20,
  );
  img.drawLine(
    image,
    x1: 612,
    y1: 512,
    x2: 572,
    y2: 552,
    color: color,
    thickness: 20,
  );
}
